/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecom.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author simon
 */
@Entity
@Table(name = "product_store")
@NamedQueries({
    @NamedQuery(name = "ProductStore.findAll", query = "SELECT p FROM ProductStore p"),
    @NamedQuery(name = "ProductStore.findByStoreId", query = "SELECT p FROM ProductStore p WHERE p.productStorePK.storeId = :storeId"),
    @NamedQuery(name = "ProductStore.findByProductId", query = "SELECT p FROM ProductStore p WHERE p.productStorePK.productId = :productId"),
    @NamedQuery(name = "ProductStore.findByStock", query = "SELECT p FROM ProductStore p WHERE p.stock = :stock"),
    @NamedQuery(name = "ProductStore.findByPrice", query = "SELECT p FROM ProductStore p WHERE p.price = :price")})
public class ProductStore implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductStorePK id;
    @Column(name = "stock")
    private Integer stock;
    @Column(name = "price")
    private Double price;
    @JoinColumn(name = "product_id", referencedColumnName = "idProduct", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "store_id", referencedColumnName = "idStore", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Store store;

    public ProductStore() {
    }

    public ProductStore(ProductStorePK productStorePK) {
        this.id = productStorePK;
    }

    public ProductStore(int storeId, int productId) {
        this.id = new ProductStorePK(storeId, productId);
    }

    public ProductStorePK getId() {
        return id;
    }

    public void setId(ProductStorePK productStorePK) {
        this.id = productStorePK;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Store getStore() {
        return store;
    }

    public void setStore(Store store) {
        this.store = store;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductStore)) {
            return false;
        }
        ProductStore other = (ProductStore) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        
        
        return "ecom.dao.hbm.ProductStore[productStorePK=" + id + "; price=" + price + "; stock="+ stock + "\n"
                + "product=" + product + "\n"
                + "store=" + store + "]\n";
    }

}
